package com.transaction.demo.test;

import java.util.ArrayList;
import java.util.List;

public class Digui {
    public static void main(String[] args){
         System.out.println("getAll=="+getAllCombinations());
    }

    public static List<String> getAllCombinations() {
        // 定义10个字母数组
        char[] alphabet = new char[10];
        for (int i = 0; i < 10; i++) {
            alphabet[i] = (char) ('a' + i);
        }
        // 定义结果列表
        List<String> result = new ArrayList<>();
        // 从长度1到长度10生成所有组合
        for (int i = 1; i <= 10; i++) {
            getCombinations(alphabet, "", i, result);
        }
        return result;
    }

    private static void getCombinations(char[] alphabet, String prefix, int k, List<String> result) {
        if (k == 0) {
            result.add(prefix);
            return;
        }
        for (int i = 0; i < 10; i++) {
            // 避免重复，只向后添加字母
            if (prefix.length() == 0 || alphabet[i] > prefix.charAt(prefix.length() - 1)) {
                getCombinations(alphabet, prefix + alphabet[i], k - 1, result);
            }
        }
    }
}
